package my.poemhelper.dao;

import my.poemhelper.vo.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Component;

@Component
public class UserDaoImpl implements UserDao {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public User getUser(String userName) {
		String sql = "select * from user where userName='"+userName+"'";
		
		SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
		
		if(rs.next()){
			User u = new User();
			u.setNickName(rs.getString("nickName"));
			u.setUserName(rs.getString("username"));
			u.setPassword(rs.getString("password"));
			u.setId(rs.getLong("id"));
			return u;
		}
		return null;
	}

}
